import React from 'react';
import Loadable from 'react-loadable';

import './WeaLicenseSubmit.less';

const loadable = (loader, loading = () => null) => Loadable({ loader, loading });
const WeaLicenseSubmit = loadable(() => import('./WeaLicenseSubmit'));
const WeaLicenseSubmitCluster = loadable(() => import('./WeaLicenseSubmitCluster'));

class Index extends React.Component {
  constructor(props) {
    super(props);
    const { location = {}, visible = false } = props;
    const { query = {} } = location;
    const { display = '' } = query;
    this.state = { display, visible, addr: '' };
  }

  render() {
    const { display, visible, addr } = this.state;
    if (display == 'page' || visible) {
      if (addr) {
        return <WeaLicenseSubmitCluster ecId={`${this && this.props && this.props.ecId || ''}_WeaLicenseSubmitCluster@e69ywi`} {...this.props} display={display} visible={visible} addr={addr} onHide={this.onHide} />;
      }
        return <WeaLicenseSubmit ecId={`${this && this.props && this.props.ecId || ''}_WeaLicenseSubmit@3aksg7`} {...this.props} display={display} visible={visible} onHide={this.onHide} />;
    }
      return null;
  }

  onShow = (addr = '') => {
    this.setState({ visible: true, addr });
  };

  onHide = () => {
    this.setState({ visible: false });
  };
}

export default Index;
